package com.gudy.gateway.bean;


import com.google.common.collect.Lists;
import thirdpart.order.OrderCmd;

import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class OrderCmdContainer {

    private static OrderCmdContainer instance = new OrderCmdContainer();

    private OrderCmdContainer(){}

    public static OrderCmdContainer getInstance(){
        return instance;
    }

    private final BlockingQueue<OrderCmd> queue = new LinkedBlockingQueue<>();

    public boolean cache(OrderCmd cmd){
        return queue.offer(cmd);
    }

    public List<OrderCmd> getAll(){
        List<OrderCmd> msgList = Lists.newArrayList();
        int count = queue.drainTo(msgList);
        return count==0?null:msgList;
    }

    public int size(){
        return queue.size();
    }
}
